package com.sgzn.sgpay.service.impl;

import com.sgzn.sgpay.model.request.SgsUserDiscRuleQueryRequest;
import com.sgzn.sgpay.model.request.SgsUserDiscountRuleQueryRequest;
import com.sgzn.sgpay.model.response.SgsResultResponse;
import com.sgzn.sgpay.model.response.vo.UserDiscountRuleVo;
import com.sgzn.sgpay.persistence.dao.TUserDiscountRuleMapper;
import com.sgzn.sgpay.persistence.domain.TUserDiscountRule;
import com.sgzn.sgpay.persistence.domain.TUserDiscountRuleExample;
import com.sgzn.sgpay.service.SgsUserDiscountRuleService;
import com.sgzn.sgpay.service.support.SgsResponseUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by linliangfang 13580393408
 * DATETIME:2018/6/17 16:34
 * Description:
 */
@Service
public class SgsUserDiscountRuleServiceImpl implements SgsUserDiscountRuleService {

    @Resource
    private TUserDiscountRuleMapper tUserDiscountRuleMapper;

    @Override
    public SgsResultResponse<List<UserDiscountRuleVo>> queryDiscountRule(SgsUserDiscountRuleQueryRequest sgsUserDiscountRuleQueryRequest){
        TUserDiscountRuleExample tUserDiscountRuleExample = new TUserDiscountRuleExample();
        //返回全部
        List<TUserDiscountRule> list = tUserDiscountRuleMapper.selectByExample(tUserDiscountRuleExample) ;
        List<UserDiscountRuleVo> userDiscountRuleVoList = new ArrayList<>();
        if (list != null ){
            for (TUserDiscountRule tUserDiscountRule: list ){
                UserDiscountRuleVo userDiscountRuleVo = new UserDiscountRuleVo();
                userDiscountRuleVo.setDiscountAmount(tUserDiscountRule.getDiscountAmount().toString());
                userDiscountRuleVo.setDiscountLevel(tUserDiscountRule.getDiscountLevel());
                userDiscountRuleVoList.add(userDiscountRuleVo);
            }
        }
        return SgsResponseUtil.INSTANCE.success(userDiscountRuleVoList);

    }

    @Override
    public SgsResultResponse<List<UserDiscountRuleVo>> queryAllRule(SgsUserDiscRuleQueryRequest request) {
        TUserDiscountRuleExample tUserDiscountRuleExample = new TUserDiscountRuleExample();
        //返回全部
        List<TUserDiscountRule> list = tUserDiscountRuleMapper.selectByExample(tUserDiscountRuleExample) ;
        List<UserDiscountRuleVo> userDiscountRuleVoList = new ArrayList<>();
        if (list != null ){
            for (TUserDiscountRule tUserDiscountRule: list ){
                UserDiscountRuleVo userDiscountRuleVo = new UserDiscountRuleVo();
                userDiscountRuleVo.setDiscountAmount(tUserDiscountRule.getDiscountAmount().toString());
                userDiscountRuleVo.setDiscountLevel(tUserDiscountRule.getDiscountLevel());
                userDiscountRuleVoList.add(userDiscountRuleVo);
            }
        }
        return SgsResponseUtil.INSTANCE.success(userDiscountRuleVoList);
    }

}
